package com.lijie.ljblog.util;

import org.springframework.beans.BeanUtils;

import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
 * @description: 集合工具
 */
public class BeanListUtils extends BeanUtils {

    /**
     * 转换对象 list
     *
     * @param sources        源对象list
     * @param targetSupplier 目标对象供应方 new
     * @param <S>            源对象类型
     * @param <T>            目标对象类型
     * @return 目标对象list
     */
    public static <S, T> List<T> copyListProperties(List<S> sources, Supplier<T> targetSupplier) {
        if (null == sources || null == targetSupplier) {
            return Collections.emptyList();
        }

        return sources.stream().map(s -> {
            T target = targetSupplier.get();
            copyProperties(s, target);
            return target;
        }).collect(Collectors.toList());
    }


}
